package mybaits;

import java.util.List;

public class Main {
    public static void main(String[] args) {
        MySqlSessionFactory mySqlSessionFactory = new MySqlSessionFactory();
        UserMapper mapper = mySqlSessionFactory.getMapper(UserMapper.class);
        User user = mapper.selectById(1);
        System.out.println(user);
        User user1 = mapper.selectByName("Hu");
        System.out.println(user1);
        User user2 = mapper.selectByNameAndId("Zhao Xiaoming", 1);
        System.out.println(user2);
    }
//      传统jbcc写法现在希望实现一个建议的mybatis，封装jdbc
    //System.out.println(jdbcSelectById(1));
//    private static User jdbcSelectById(int id){
//
//        String jdbcUrl = "jdbc:mysql://localhost:3306/demo";
//        String dbUser = "root";
//        String Password = "root";
//        String sql = "select * from user where id = ?";
//        try (Connection connection = DriverManager.getConnection(jdbcUrl, dbUser, Password);
//             PreparedStatement preparedStatement = connection.prepareStatement(sql)) {
//            preparedStatement.setInt(1, id);
//            ResultSet rs = preparedStatement.executeQuery();
//            while (rs.next()) {
//                return new User(rs.getInt("id"), rs.getString("name"));
//            }
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//        return null;
//    }
}
